package com.yaoli.niuke;

import java.util.*;

/**
 *
 * important
 *
 * 如果要使用到辅助类 ，那么辅助类上一定要加 static 表示静态类
 *
 * Created by will on 2017/7/31.
 */
public class MergeTable {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int count = input.nextInt();

        Map<Integer,Integer> map = new HashMap<Integer,Integer>();

        for(int i = 0 ; i< count ; i ++){
            int key = input.nextInt();

            int value = input.nextInt();

            if(map.get(key) == null){
                map.put(key,value);
            }else{
                map.put(key,map.get(key) + value);
            }
        }

        Comparator<Merge> comp = new Comparator<Merge>(){
            public int compare(Merge o1,Merge o2){
                return o1.key - o2.key;
            }
        };

        PriorityQueue<Merge> queue = new PriorityQueue<Merge>(10,comp);

        for(Integer num : map.keySet()){
            Merge m = new Merge();
            m.key = num;
            m.value = map.get(num);
            queue.add(m);
        }

        while(queue.size()!=0){
            Merge m = queue.poll();
            System.out.println(m.key+" "+m.value);
        }
    }

    static class Merge{
        public int key;
        public int value;
    }
}
